home *** CD-ROM | disk | FTP | other *** search
/ Programming Windows 95 / Programming Windows 95.iso / code / CHAP04 / EMF2.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-01  |  3.1 KB  |  101 lines

  1. /*-------------------------------------
  2.    EMF2.C -- Enhanced Metafile Demo #2
  3.              (c) Charles Petzold, 1996
  4.   -------------------------------------*/
  5.  
  6. #include <windows.h>
  7.  
  8. LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
  9.  
  10. int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  11.                     PSTR szCmdLine, int iCmdShow)
  12.      {
  13.      static char szAppName[] = "EMF2" ;
  14.      HWND        hwnd ;
  15.      MSG         msg ;
  16.      WNDCLASSEX  wndclass ;
  17.  
  18.      wndclass.cbSize        = sizeof (wndclass) ;
  19.      wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
  20.      wndclass.lpfnWndProc   = WndProc ;
  21.      wndclass.cbClsExtra    = 0 ;
  22.      wndclass.cbWndExtra    = 0 ;
  23.      wndclass.hInstance     = hInstance ;
  24.      wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
  25.      wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
  26.      wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
  27.      wndclass.lpszMenuName  = NULL ;
  28.      wndclass.lpszClassName = szAppName ;
  29.      wndclass.hIconSm       = LoadIcon (NULL, IDI_APPLICATION) ;
  30.  
  31.      RegisterClassEx (&wndclass) ;
  32.  
  33.      hwnd = CreateWindow (szAppName, "Enhanced Metafile Demo #2",
  34.                           WS_OVERLAPPEDWINDOW,
  35.                           CW_USEDEFAULT, CW_USEDEFAULT,
  36.                           CW_USEDEFAULT, CW_USEDEFAULT,
  37.                           NULL, NULL, hInstance, NULL) ;
  38.  
  39.      ShowWindow (hwnd, iCmdShow) ;
  40.      UpdateWindow (hwnd) ;
  41.  
  42.      while (GetMessage (&msg, NULL, 0, 0))
  43.           {
  44.           TranslateMessage (&msg) ;
  45.           DispatchMessage (&msg) ;
  46.           }
  47.      return msg.wParam ;
  48.      }
  49.  
  50. LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
  51.      {
  52.      HDC          hdc, hdcEMF ;
  53.      HENHMETAFILE hemf ;
  54.      PAINTSTRUCT  ps ;
  55.      RECT         rect ;
  56.  
  57.      switch (iMsg)
  58.           {
  59.           case WM_CREATE:
  60.                hdcEMF = CreateEnhMetaFile (NULL, "emf2.emf", NULL,
  61.                                            "EMF2\0EMF Demo #2\0") ;
  62.  
  63.                Rectangle (hdcEMF, 100, 100, 200, 200) ;
  64.  
  65.                MoveToEx  (hdcEMF, 100, 100, NULL) ;
  66.                LineTo    (hdcEMF, 200, 200) ;
  67.  
  68.                MoveToEx  (hdcEMF, 200, 100, NULL) ;
  69.                LineTo    (hdcEMF, 100, 200) ;
  70.  
  71.                hemf = CloseEnhMetaFile (hdcEMF) ;
  72.  
  73.                DeleteEnhMetaFile (hemf) ;
  74.                return 0 ;
  75.  
  76.           case WM_PAINT:
  77.                hdc = BeginPaint (hwnd, &ps) ;
  78.  
  79.                GetClientRect (hwnd, &rect) ;
  80.  
  81.                rect.left   =     rect.right  / 4 ;
  82.                rect.right  = 3 * rect.right  / 4 ;
  83.                rect.top    =     rect.bottom / 4 ;
  84.                rect.bottom = 3 * rect.bottom / 4 ;
  85.  
  86.                hemf = GetEnhMetaFile ("emf2.emf") ;
  87.  
  88.                PlayEnhMetaFile (hdc, hemf, &rect) ;
  89.  
  90.                DeleteEnhMetaFile (hemf) ;
  91.  
  92.                EndPaint (hwnd, &ps) ;
  93.                return 0 ;
  94.  
  95.           case WM_DESTROY:
  96.                PostQuitMessage (0) ;
  97.                return 0 ;
  98.           }
  99.      return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
  100.      }
  101.